//
//  SettingVC.m
//  liBaQiang
//
//  Created by 奇林刘 on 2018/11/12.
//  Copyright © 2018年 liu. All rights reserved.
//

#import "SettingVC.h"
#import "SettingVCRegularButton.h"

@interface SettingVC ()

@property (nonatomic, strong) NSMutableArray<SettingVCRegularButton *> *buttons;
@property (weak, nonatomic) IBOutlet UIButton *logoutButton;

@end

@implementation SettingVC

#pragma mark - Construction Script
- (void)configSelf {
    self.title = @"设置";
    self.view.fp_backgroundColor(HexadecimalColor(@"#F5F6F8"));
}

- (void)allocateComponents {
    self.buttons = [NSMutableArray array];
    for (NSDictionary *buttonDictionary in [self buttonDictionarys]) {
        SettingVCRegularButton *button = [[SettingVCRegularButton alloc] initWithName:buttonDictionary[@"name"] event:buttonDictionary[@"event"]];
        [self.view addSubview:button];
        [self.buttons addObject:button];
    }
}

- (void)layoutComponents {
    for (int i = 0; i < self.buttons.count; i++) {
        [self.buttons[i] mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            if (i == 0) {
                make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(RPX(15));
            } else {
                make.top.equalTo(self.buttons[i - 1].mas_bottom);
            }
        }];
    }
    
    [self.logoutButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.buttons.lastObject.mas_bottom).offset(RPX(20));
        make.width.equalTo(@(RPX(345)));
        make.height.equalTo(@(RPX(44)));
    }];
}

- (void)configComponents {
    [self.logoutButton setTitle:@"退出登录" forState:UIControlStateNormal];
    [self.logoutButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.logoutButton.fp_cornerRadius(RPX(4)).fp_backgroundColor(HexadecimalColor(@"#2D5898"));
}

#pragma mark - Events
- (IBAction)onLogoutButtonTap:(id)sender {
    NSLog(@"logout");
    SaveUserToken(nil);
    [HandyMethods reloadApp];
}

#pragma mark - Methods
- (NSArray<NSDictionary *> *)buttonDictionarys {
    NSArray<NSDictionary *> *array = @[@{@"name" : @"修改登录密码",
                                         @"event" : [self eventChangePassword]
                                         },
                                       @{@"name" : @"更换验证手机",
                                         @"event" : [self eventChangePhone]
                                         },
                                       @{@"name" : @"指纹设置",
                                         @"event" : [self eventSetFingerprint]
                                         },
                                       @{@"name" : @"U盾认证",
                                         @"event" : [self eventGoUShield]
                                         },
                                       @{@"name" : @"关于我们",
                                         @"event" : [self eventAboutUs]
                                         }];
    return array;
}

- (void (^)(void))eventChangePassword {
    void (^block)(void) = ^(void) {
        NSLog(@"eventChangePassword");
    };
    return block;
}

- (void (^)(void))eventChangePhone {
    void (^block)(void) = ^(void) {
        NSLog(@"eventChangePhone");
    };
    return block;
}

- (void (^)(void))eventSetFingerprint {
    void (^block)(void) = ^(void) {
        NSLog(@"eventSetFingerprint");
    };
    return block;
}

- (void (^)(void))eventGoUShield {
    void (^block)(void) = ^(void) {
        NSLog(@"eventGoUShield");
    };
    return block;
}

- (void (^)(void))eventAboutUs {
    void (^block)(void) = ^(void) {
        NSLog(@"eventAboutUs");
    };
    return block;
}

@end
